<!-- #events -->
<article id="events" class="events">
    <div class="container">
        <h1 class="title-primary">Events</h1>
        <div class="row">
            <?php if($list_event_count > 0): ?>
            
                <!-- .list-events -->
                <div class="col-md-8">
                    <!-- .list-event-wrap -->
                    <div class="list-blog-wrap">
                        <!-- Event data will be load with AJAX and append on ul below -->
                        <ul class="list-blog" id="event_list"></ul>
                        <div id="pagination_events"></div>
                        <!-- Event data -->
                    </div>
                    <!-- /.list-event-wrap -->
                </div>
                <!-- /.list-news -->
    
                <!-- .sidebar -->
                <div class="col-md-4 sidebar">
                    <!-- .search-widget -->
    				<div class="widget search-widget">
    					<div class="form-group input-group">
    						<input type="text" value="" id="search_event" name="search_event" class="form-control" placeholder="Search..." />
    						<button class="btn btn-primary input-addon" id="btn_search_event" style="padding: 3px 12px !important;">
    							<i class="glyphicon icon-search"></i>
    						</button>
    					</div>
    				</div>
    				<!-- /.search-widget -->
                    
                    <!-- .widget -->
                    <?php 
                        $date           = time();
                        $day            = date('d', $date) ; 
                        $month          = date('m', $date) ;
                        $year           = date('Y', $date) ;
                        
                        $month_list     = array(
                            '01'        => 'Januari', 
                            '02'        => 'Februari', 
                            '03'        => 'Maret', 
                            '04'        => 'April', 
                            '05'        => 'Mei', 
                            '06'        => 'Juni', 
                            '07'        => 'Juli',
                            '08'        => 'Agustus', 
                            '09'        => 'September', 
                            '10'        => 'Oktober', 
                            '11'        => 'Nopember', 
                            '12'        => 'Desember'
                        );
                        
                        if( !empty($list_event_archived) ){
                            echo '<div class="widget">';
                                echo '<span class="widget-title">Archives</span>';
                                echo '<ul class="list-default">';
                                    foreach($list_event_archived as $archive){
                                        echo '<li><a href="#" class="event_archive'. ( $archive == $month_list[$month] ? ' archive_active' : '' ) .'" title="'.$archive.'">'.$archive.' '.$year.'</a></li>';
                                    }
                                echo '</ul><hr />';
                            echo '</div>';
                        }
                    ?>
    				<!-- /.widget -->
                
                    <!-- .widget -->
                    <div class="widget">
                        <!-- #calendar-wrap -->
                        <span class="widget-title">Calendar</span>
                        <div id="calendar_wrap" class="calendar_wrap">                       
                            <!-- #calender-slides -->
                            <div id="calendar-slides" class="flex-simple">
                                <ul class="slides">
                                    <li>
                                        <div class="calendar-content">
                                        <?php
                                            //Here we generate the first day of the month 
                                            $first_day      = mktime(0,0,0,$month, 1, $year) ; 
    
                                            //This gets us the month name 
                                            $month_title    = date('M', $first_day) ;
    
                                            //Here we find out what day of the week the first day of the month falls on 
                                            $day_of_week    = date('D', $first_day) ; 
    
                                            //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
                                            switch($day_of_week){ 
                                                case "Sun": $blank = 0; break; 
                                                case "Mon": $blank = 1; break; 
                                                case "Tue": $blank = 2; break; 
                                                case "Wed": $blank = 3; break; 
                                                case "Thu": $blank = 4; break; 
                                                case "Fri": $blank = 5; break; 
                                                case "Sat": $blank = 6; break; 
                                            }
    
                                            //We then determine how many days are in the current month
                                            $days_in_month  = cal_days_in_month(0, $month, $year) ;
                                            
                                            //This counts the days in the week, up to 7
                                            $day_count      = 1;
                                            
                                            //sets the first day of the month to 1 
                                            $day_num        = 1;
                                            
                                            echo '<time datetime="'. date("Ym",$date) . '" class="calendar-month text-time">';
                                                echo '<span class="h2">'. $month_title . '</span><span>'. date("Y",$date) .'</span>';
                                            echo '</time>';
                                            
                                            echo '<table>';
                                                echo '<thead>';
                                                    echo '<tr>';
                                                        echo '<th scope="col" title="Monday">Mon</th>';
                                                        echo '<th scope="col" title="Tuesday">Tue</th>';
                                                        echo '<th scope="col" title="Wednesday">Wed</th>';
                                                        echo '<th scope="col" title="Thursday">Thu</th>';
                                                        echo '<th scope="col" title="Friday">Fri</th>';
                                                        echo '<th scope="col" title="Saturday">Sat</th>';
                                                        echo '<th scope="col" title="Sunday">Sun</th>';
                                                    echo '</tr>';
                                                echo '</thead>';
                                                
                                                echo '<tbody>';
                                                    echo "<tr>";
        
                                                    //first we take care of those blank days
                                                    while ( $blank > 0 ) 
                                                    { 
                                                        echo "<td></td>"; 
                                                        $blank = $blank - 1; 
                                                        $day_count++;
                                                    } 
        
                                                    //count up the days, untill we've done all of them in the month
                                                    while ( $day_num <= $days_in_month ) 
                                                    {
                                                        $event_date     = $year . '-' . $month . '-' . sprintf("%02s", $day_num);
                                                        $event_count    = get_events_by_day($event_date);
                                                        $event_title    = ( $event_count > 1 ? 'There is '.$event_count.' events' : 'There is '.$event_count.' event');
                                                        
                                                        if($event_count > 0){
                                                            echo '<td>';
                                                                echo '<a href="#" title="'.$event_title.'" data-toggle="tooltip" data-container="body" class="event_date">';
                                                                    echo '<span class="event-date">'.$day_num.'</span>';
                                                                    echo '<input class="event-date-val" type="hidden" name="event_date" value="'.$month .'-'. sprintf("%02s", $day_num) .'" />';
                                                                echo '</a>';
                                                            echo '</td>';
                                                        }else{
                                                            echo '<td><span class="event-date">'.$day_num.'</span></td>'; 
                                                        }
                                                        
                                                        $day_num++; 
                                                        $day_count++;
                                                        
                                                        //Make sure we start a new row every week
                                                        if ($day_count > 7)
                                                        {
                                                            echo "</tr><tr>";
                                                            $day_count = 1;
                                                        }
                                                    }
    
                                                    //Finaly we finish out the table with some blank details if needed
                                                    while ( $day_count >1 && $day_count <=7 ) 
                                                    { 
                                                        echo "<td> </td>"; 
                                                        $day_count++;
                                                    } 
                                                    
                                                    echo "</tr>";
                                                echo '</tbody>';
                                            echo '</table>';
                                        ?>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            <!-- /#calender-slides -->
                        </div>
                        <!-- /#calendar-wrap -->
                    </div>
                    <!-- /.widget -->
                </div>
                <!-- /.sidebar -->
            
            <?php else: ?>
            
                <div class="col-md-12">
                    <div class="show-more">
                        <div class="show-more-inner text-center">
                            <a href="#" class="btn-showmore btn btn-primary btn-sm disabled">No Events</a>
                        </div>
                    </div>
                </div>
            
            <?php endif ?>
        </div>
    </div>
</article>
<!-- /#events -->